﻿using JinfuyuanProject.Entity;
using JinfuyuanProject.Service;
using JinfuyuanProject.Service.Interface;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Web;
using System.Web.Mvc;

namespace JinfuyuanProject.Controllers
{
    public class ServiceListController : Controller
    {
        private readonly IServicesService _servicesService;
        public ServiceListController(IServicesService servicesService)
        {
            _servicesService = servicesService;
        }
        // GET: ServiceList


        #region 页面
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult Detail()
        {
            return View();
        }
        public ActionResult ServiceList()
        {
            return View();
        }

        public ActionResult Edit(int id)
        {
            ViewBag.Id = id;
            return View();
        }
        #endregion

        #region 接口

        public JsonResult DataList(int page = 1, int limit = 5, string serviceName = null)  //服务表格
        {
            ServicesFilter filter = new ServicesFilter();
            filter.page = page;
            filter.limit = limit;
            filter.ServiceName = serviceName; // 添加服务名称搜索条件
            Hashtable ht = _servicesService.ListData(filter);
            return Json(ht, JsonRequestBehavior.AllowGet);
        }

        public JsonResult DataInsert(Services service)   //服务添加
        {
            Hashtable result = _servicesService.InsertData(service);
            return Json(result, JsonRequestBehavior.AllowGet);
        }

        [HttpPost]
        public JsonResult DeleteData(int id)
        {
            Hashtable result = _servicesService.DeleteData(id);
            return Json(result, JsonRequestBehavior.AllowGet);
        }

        [HttpPost]
        public JsonResult DataEdit(Services service)
        {
            Hashtable result = _servicesService.EditData(service);
            return Json(result, JsonRequestBehavior.AllowGet);
        }

        [HttpGet]
        public JsonResult GetService(int id)
        {
            Hashtable result = _servicesService.GetServiceById(id);
            return Json(result, JsonRequestBehavior.AllowGet);
        }

        #endregion
    }
}
